{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-input-inline layui-form">
                            <select name="role" lay-search="">
                                <option  value="">不限等级</option>
                                <option  value="1">普通用户</option>
                                <option  value="2">合伙人用户</option>
                            </select>
                        </div>
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="用户名/手机号"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="imgTpl">
                        <img src="{{d.user_image}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <!--角色模板-->
                    <script type="text/html" id="titleTpl">
                        {{# if(d.user_gender == 1){ }}
                        男
                        {{# }else{ }}
                        女
                        {{# } }}
                    </script>
                    <script type="text/html" id="levelTpl">
                        {{# if(d.user_level == 1){ }}
                        普通用户
                        {{# }else if(d.user_level == 2){ }}
                        城市合伙人用户
                        {{# }else if(d.user_level == 3){ }}
                        事业合伙人用户
                        {{# }else if(d.user_level == 4){ }}
                        推广合伙人用户
                        {{# }else{ }}
                        店主
                        {{# } }}
                    </script>
                    <!--状态模板-->
                    <script type="text/html" id="staBar">
                        {{# if(d.id!==1){ }}
                        <input type="checkbox" value="{{d.user_id}}"  lay-skin="switch"  lay-text="正常|冻结" lay-filter="OnOff"{{ d.user_status == 1 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <script type="text/html" id="cityBar">
                        {{# if(d.id!==1){ }}
                        <input type="checkbox" value="{{d.user_id}}"  lay-skin="switch"  lay-text="启用|禁用" lay-filter="OnOff1"{{ d.user_city_man == 2 ? 'checked' : '' }}  >
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.href('{:url('memberEdit')}?id={{d.user_id}}')" class="btn btn-primary btn-xs m-r-xs" >编辑</a>
                        <a href="javascript:;" onclick="son({{d.user_id}})" class="btn btn-primary btn-xs m-r-xs" {:session("?security")? '' : 'style="display:none;"'}>排序</a>
                        <a href="javascript:;" onclick="wk.href('{:url('memberDetail')}?user_id={{d.user_id}}')" class="btn btn-primary btn-xs m-r-xs" >积分获取详情</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var show = "{$show}";
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
            if (show == true) {
                table.render({
                    elem: '#test'
                    , url: '{:url("Member/index")}'
                    ,response: {
                        statusCode: 220 //成功的状态码，默认：0
                    }
                    , page: true
                    , size: 'lg' //sm小尺寸的表格 lg大尺寸
                    , cellMinWidth: 150
                    , limits: [5, 10, 15, 20, 25, 30]
                    , limit: 10
                    , loading: true
                    , id: 'testReload'
                    , cols: [[
                        {type:'numbers', width: 80, title: '序号'}
                        , {field: 'user_username', width: '', title: '用户名', align: 'center'}
                        , {field: 'user_image', width: 90, title: '头像', align: 'center', templet: '#imgTpl'}
                        , {field: 'user_gender', width: '', title: '性别', align: 'center', templet: '#titleTpl'}
                        , {field: 'district', width: '', title: '地区', align: 'center'}
                        , {field: 'user_phone', width: '', title: '手机号', align: 'center'}
                        , {field: 'user_level', width: '', title: '等级', align: 'center', templet: '#levelTpl'}
                        , {field: 'user_money_balance', width: '', title: '可提现现金余额', align: 'center'}
                        , {field: 'user_balance', width: '', title: '可提现余额', align: 'center'}
                        , {field: 'user_balance_yet', width: '', title: '已提现余额', align: 'center'}
                        , {field: 'user_integral', width: '', title: '积分数量', align: 'center'}
                        , {field: 'user_m_pool_money', width: '', title: '产品池余额', align: 'center'}
                        , {field: 'user_time', width: '', title: '注册时间', align: 'center'}
                        , {field: 'user_status',fixed: '', width: 100, title: '状态', align: 'center', templet: '#staBar'}
                        <!-- , {field: 'user_city_man',fixed: 'right', width: 100, title: '城主', align: 'center', templet: '#cityBar'} -->
                        , {fixed: 'right', width: 210, title: '操作', align: 'center', toolbar: '#opeBar'}
                    ]],
                    done: function (res, curr, count) {
                        $('.img-circle').viewer();
                    }
                });
            }else{
                table.render({
                    elem: '#test'
                    , url: '{:url("Member/index")}'
                    ,response: {
                        statusCode: 220 //成功的状态码，默认：0
                    }
                    , page: true
                    , size: 'lg' //sm小尺寸的表格 lg大尺寸
                    , cellMinWidth: 150
                    , limits: [5, 10, 15, 20, 25, 30]
                    , limit: 10
                    , loading: true
                    , id: 'testReload'
                    , cols: [[
                        {type:'numbers', width: 80, title: '序号'}
                        , {field: 'user_username', width: '', title: '用户名', align: 'center'}
                        , {field: 'user_image', width: 90, title: '头像', align: 'center', templet: '#imgTpl'}
                        , {field: 'user_gender', width: '', title: '性别', align: 'center', templet: '#titleTpl'}
                        , {field: 'district', width: '', title: '地区', align: 'center'}
                        , {field: 'user_phone', width: '', title: '手机号', align: 'center'}
                        , {field: 'user_level', width: '', title: '等级', align: 'center', templet: '#levelTpl'}
                        , {field: 'user_balance', width: '', title: '可提现余额', align: 'center'}
                        , {field: 'user_balance_yet', width: '', title: '已提现余额', align: 'center'}
                        , {field: 'user_integral', width: '', title: '积分数量', align: 'center'}
                        , {field: 'user_time', width: '', title: '注册时间', align: 'center'}
                        , {field: 'user_status',fixed: 'right', width: 100, title: '状态', align: 'center', templet: '#staBar'}
                        , {field: 'user_city_man',fixed: 'right', width: 100, title: '城主', align: 'center', templet: '#cityBar'}
                        
                    ]],
                    done: function (res, curr, count) {
                        $('.img-circle').viewer();
                    }
                });
            }
        //监听状态开关操作
        form.on('switch(OnOff)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 1: num = 2;
            //用户状态
            wk.status(this.value,num, '{:url("memberStatus")}',obj);
        });
        form.on('switch(OnOff1)', function (obj) {
            var num = '';
            obj.elem.checked == true? num = 2: num = 1;
            //用户状态
            wk.status(this.value,num, '{:url("cityMan")}',obj);
        });

        //批量操作
        var $ = layui.$, active = {
            getCheckData: function(){
                //批量删除
                wk.batchDel(getIds(),"{:url('batchDelUser')}");
            }
            ,forbiddenAll: function(){
                //批量禁用
                wk.batchForbidden(getIds(),2,"{:url('forbiddenAdmin')}");
            }
            ,usingAll: function(){
                //批量启用
                wk.usingAll(getIds(),1,"{:url('usingAdmin')}");
            }
            ,excelAll: function(){
                //导出Excel
                wk.excelAll(getIds(),$('#layuiForm').serialize(),"{:url('excelAdmin')}");
            }
        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var getIds = function () {
            var ids = [];
            var checkStatus = table.checkStatus('testReload')
                ,data = checkStatus.data;
            $.each(data,function(index,item){
                ids.push(item['id'])
            });
            return ids;
        }
    });

    function son(shop_id) {
        layer.prompt({
            formType: 2,
            title: '修改排序值',
            area: ['200px', '50px'],
            btn: ['确认', '取消'],
            maxlength:11,
        },function(value, index, elem){
            var pattern = /^[1-9]\d*$/;
            if(!pattern.test(value)){
                wk.error('请填写正确的排序值');
                return;
            }
            send1(shop_id,value);
            layer.close(index);
        });
    }
    function send1(shop_id,value){
        $.ajax({
            url: "{:url('addSort')}",
            type: "post",
            dataType: "json",
            data: {id:shop_id,value:value},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
</script>
</body>
</html>